<script>
	var iosSessionId = 0;
	import Vue from 'vue'


	export default {
		onLaunch: function() {
			var that = this

			// #ifdef APP-PLUS
			plus.push.addEventListener('click', function(msg) {
				// console.log('用户点击了', msg)
				// 安卓离线通知被点击可能会触发两次click,第一次的msg.payload为莫名obj
				if ((msg.payload && Object.prototype.toString.call(msg.payload) !== '[object Object]') ||
					iosSessionId) {
					let messageShow = () => {
						let sessionId = (iosSessionId ? iosSessionId : msg.payload)
						if (parseInt(sessionId) == 0) {
							uni.switchTab({
								url: '/pages/message/message'
							})
							return;
						}
						uni.navigateTo({
							url: '/sub/session-info/session-info?id=' + sessionId
						})
					}
					let pages = getCurrentPages(),
						page = pages[pages.length - 1]
					if (page && page.route == 'pages/message/message') {
						messageShow()
					} else {
						that.ws.messageReady = messageShow
					}
				}
			}, false)

			let platform = that.ws.userPlatform ? that.ws.userPlatform : uni.getSystemInfoSync().platform
			if (platform == 'ios') {
				plus.push.addEventListener("receive", function(msg) {
					if ('ignore' == msg.payload) {

					} else {
						//接收透传消息
						iosSessionId = msg.payload;
						plus.push.createMessage(msg.content, 'ignore', {
							title: msg.title,
							cover: false
						});
					}
				}, false);
			}
			// #endif

			uni.onNetworkStatusChange(function(res) {
				if (res.isConnected) {
					const userinfo = uni.getStorageSync('userinfo');
					if (userinfo) {
						that.ws.init(userinfo.token, userinfo.auth_token)
					}
				} else {
					that.ws.socketTask.close()
					that.ws.socketOpen = false
					that.ws.checkNetwork()
				}
			});
		},

		onShow: function(query) {
			if (query.path != 'pages/login/index' &&
				query.path != 'sub/center/register' &&
				query.path != 'sub/center/realname' &&
				query.path != 'sub/center/realnamenext') {
				this.ws.pageRefresh.message = true
				this.ws.pageRefresh.sessionInfo = true
				// this.checkLogin()
			}
		},
		methods: {

		}
	}
</script>

<style lang="scss">
	@import "uview-ui/index.scss";

	body {
		background-color: #fafafa;
		font-size: 15px;
	}


	.user-status-0 {
		color: $--gray !important;
	}

	.user-status-1 {
		color: #CCCCCC !important;
	}

	.user-status-2 {
		color: #FF647E !important;
	}

	.user-status-3 {
		color: #FF9C4E !important;
	}

	.im-data-none {
		display: block;
		line-height: 100rpx;
		text-align: center;
		font-size: 28rpx;
		color: $--gray;
	}

	.btn {
		margin: 0 auto;
		border-radius: 10rpx;
		margin-top: 40rpx;
		width: 90vw;
		height: 50px;
		text-align: center;
		line-height: 50px;
		color: #FFF;
		background-color: #6EC9E1;
	}

	.button {
		display: flex;
		justify-content: flex-end;
		align-items: center;
		background-color: #FFF;
		color: #3D3D3D;

		.b-s {
			position: relative;
			z-index: 999;
			border-radius: 43.7px;
			box-sizing: border-box;
			border: 0.5px solid #D8D8D8;
			padding: 0 20rpx;
			margin-left: 20rpx;
			height: 30px;
			line-height: 30px;
			min-width: 76px;
			text-align: center;
		}
	}

	.click,
	.btn,
	.button {
		animation: throttle 1.2s step-end forwards;
	}

	.click:active,
	.btn:active,
	.button:active {
		animation: none;
	}

	@keyframes throttle {
		from {
			pointer-events: none;
		}

		to {
			pointer-events: all;
		}
	}
</style>